{% extends "base.html" %} {% block title %}健康知识管理 - 运动健康管理系统{%
endblock %} {% block content %}
<div class="container py-5">
  <nav aria-label="breadcrumb">
    <ol class="breadcrumb">
      <li class="breadcrumb-item">
        <a href="{{ url_for('admin_dashboard') }}">管理员仪表盘</a>
      </li>
      <li class="breadcrumb-item active" aria-current="page">健康知识管理</li>
    </ol>
  </nav>

  <div class="d-flex justify-content-between align-items-center mb-4">
    <h1 class="mb-0"><i class="bi bi-journal-text"></i> 健康知识管理</h1>
    <a href="{{ url_for('admin_add_knowledge') }}" class="btn btn-primary">
      <i class="bi bi-plus-circle"></i> 添加新文章
    </a>
  </div>


  <!-- 搜索框 -->
  <div class="row mb-4">
    <div class="col-md-6">
      <form
        action="{{ url_for('admin_knowledge') }}"
        method="GET"
        class="d-flex">
        <input
          type="text"
          name="keyword"
          class="form-control me-2"
          placeholder="搜索文章..."
          value="{{ keyword if keyword }}" />
        <button type="submit" class="btn btn-primary">搜索</button>
      </form>
    </div>
  </div>

  <div class="card shadow">
    <div class="card-body">
      <div class="table-responsive">
        <table class="table table-hover">
          <thead>
            <tr>
              <th>标题</th>
              <th>分类</th>
              <th>发布时间</th>
              <th>浏览次数</th>
              <th>操作</th>
            </tr>
          </thead>
          <tbody>
            {% for article in articles %}
            <tr>
              <td>{{ article.title }}</td>
              <td>{{ article.category }}</td>
              <td>{{ article.created_at.strftime('%Y-%m-%d %H:%M') }}</td>
              <td>{{ article.view_count }}</td>
              <td>
                <div class="d-flex">
                  <a
                    href="{{ url_for('admin_edit_knowledge', article_id=article.id) }}"
                    class="btn btn-sm btn-warning me-2"
                    >编辑</a
                  >
                  <form
                    action="{{ url_for('admin_delete_knowledge', article_id=article.id) }}"
                    method="POST"
                    onsubmit="return confirm('确定要删除这篇文章吗？此操作不可恢复！');">
                    <button type="submit" class="btn btn-sm btn-danger">
                      删除
                    </button>
                  </form>
                </div>
              </td>
            </tr>
            {% else %}
            <tr>
              <td colspan="4" class="text-center">暂无健康知识文章</td>
            </tr>
            {% endfor %}
          </tbody>
        </table>
      </div>
    </div>
  </div>
</div>
{% endblock %}
